/*
 * This file is part of "IdeWiki" project.
 *
 * Copyright (c) 2008 Hendrik Ebel
 * All Rights Reserved.
 *
 * Please visit http://code.google.com/p/idewiki for updates and contact.
 *
 * --LICENSE NOTICE--
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; If not, see <http://www.gnu.org/licenses/>.
 * --LICENSE NOTICE--
 */
package ws.ebel.idewiki.xmlrpc;

import java.text.SimpleDateFormat;
import java.util.Date;

import ws.ebel.idewiki.util.CommonHelper;

/**
 * The Class SnipBean.
 */
public class SnipBean {

    /** The Constant DATE_FORMAT. */
    private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    
    /** The content. */
    private String content;
    
    /** The c user. */
    private String cUser;
    
    /** The m user. */
    private String mUser;
    
    /** The c time. */
    private Date cTime;
    
    /** The m time. */
    private Date mTime;
    
    /** The snip name. It is encoded!*/
    private String snipName;
    
    /** The parent snip name. */
    private String parentSnipName;
    
    private String decodeSnipName;
    private String decodeParentSnipName;

    /**
     * Construtor for an edit snip.
     * 
     * @param mUser the m user
     * @param mTime the m time
     * @param snipName the snip name
     * @param cTime the c time
     * @param content the content
     * @param cUser the c user
     */
    public SnipBean(String content, String cUser, String mUser, Date cTime, Date mTime,
            String snipName) {
        this.content = content;
        this.cUser = cUser;
        this.mUser = mUser;
        this.cTime = cTime;
        this.mTime = mTime;
        this.snipName = snipName;
        decodeSnipName = CommonHelper.decode(snipName);
    }

    /**
     * Construtor  for a new snip.
     * 
     * @param snipName the snip name
     * @param parentSnipName the parent snip name
     */
    public SnipBean(String snipName, String parentSnipName) {
        this.content = "";
        this.cUser = "";
        this.mUser = "";
        this.cTime = new Date();
        this.mTime = new Date();
        this.snipName = snipName;
        this.decodeSnipName = CommonHelper.decode(snipName);
        this.parentSnipName = parentSnipName;
        this.decodeParentSnipName = CommonHelper.decode(parentSnipName);
    }

    /**
     * Gets the content.
     * 
     * @return the content
     */
    public String getContent() {
        return content;
    }

    /**
     * Gets the C time.
     * 
     * @return the C time
     */
    public Date getCTime() {
        return cTime;
    }

    /**
     * Gets the C user.
     * 
     * @return the C user
     */
    public String getCUser() {
        return cUser;
    }

    /**
     * Gets the M time.
     * 
     * @return the M time
     */
    public Date getMTime() {
        return mTime;
    }

    /**
     * Gets the formatted M time.
     * 
     * @return the formatted M time
     */
    public String getFormattedMTime() {
        SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
        return df.format(getMTime());
    }

    /**
     * Gets the formatted C time.
     * 
     * @return the formatted C time
     */
    public String getFormattedCTime() {
        SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
        return df.format(getCTime());
    }

    /**
     * Gets the M user.
     * 
     * @return the M user
     */
    public String getMUser() {
        return mUser;
    }

    /**
     * Gets the snip name.
     * 
     * @return the snip name
     */
    public String getSnipName() {
        return snipName;
    }

    /**
     * Gets the parent snip name.
     * 
     * @return the parentSnipName
     */
    public String getParentSnipName() {
        return parentSnipName;
    }

    /**
     * @return the decodeParentSnipName
     */
    public String getDecodeParentSnipName() {
        return decodeParentSnipName;
    }

    /**
     * @return the decodeSnipName
     */
    public String getDecodeSnipName() {
        return decodeSnipName;
    }

    /**
     * @param aContent the content to set
     */
    public void setContent(String aContent) {
        content = aContent;
    }

    /**
     * Set the encoded snip name and his decoded name
     * @param aSnipName the snipName to set
     */
    public void setSnipName(String aSnipName) {
        snipName = CommonHelper.encode(aSnipName.trim());
        decodeSnipName = aSnipName.trim();
    }

    /**
     * @return
     */
    public String getFullEncodeSnipName() {
        return snipName.replace(" ", CommonHelper.ENCODED_SPACE);
    }

}
